package com.huiyeji.dynamic.core;

import com.huiyeji.dynamic.core.exception.DynamicException;

public class DynamicErrorResult extends DynamicResult {

    private final String exceptionType;

    private final String exceptionMessage;

    private final int exceptionPosition;

    private final String exceptionStatement;

    public DynamicErrorResult(DynamicException exception, DynamicContext context) {
        super(exception.getCode(), false, context);
        this.exceptionMessage = exception.getMessage();
        this.exceptionType = exception.getClass().getName();
        this.exceptionPosition = context.getPointer().getCurrentPosition();
        this.exceptionStatement = context.getPointer().get().getOriginalStatement();
    }

    public DynamicErrorResult(Exception exception,DynamicContext context) {
        super(9099, false, context);
        this.exceptionMessage = exception.getMessage();
        this.exceptionType = exception.getClass().getName();
        this.exceptionPosition = context.getPointer().getCurrentPosition();
        this.exceptionStatement = context.getPointer().get().getOriginalStatement();
    }

    public String getExceptionType() {
        return exceptionType;
    }

    public String getExceptionMessage() {
        return exceptionMessage;
    }

    public int getExceptionPosition() {
        return exceptionPosition;
    }

    public String getExceptionStatement() {
        return exceptionStatement;
    }

    public void throwException(){
        throw new DynamicException(getStatus(),exceptionMessage);
    }
}
